package com.nb.demo.kafka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description: java类作用描述
 * @Author: hiven
 * @CreateDate: 2019/11/30$ 17:52$
 * @UpdateUser: yc
 * @UpdateDate: 2019/11/30$ 17:52$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@RestController
public class KafkaController {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    private AtomicInteger integer = new AtomicInteger();
    @GetMapping("produceMsg")
    public String produceMsg(){
        String uuid = UUID.randomUUID().toString().substring(0, 10)+"======"+integer.addAndGet(1);
        kafkaTemplate.send("testTopic", 0, uuid, uuid);
        return "x";
    }
}
